package com.aat.dizena.chat.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.aat.dizena.base.CommonConstant;
import com.aat.dizena.base.bean.User;
import com.aat.dizena.base.web.controller.BaseController;

@Controller
@Scope("prototype")
@RequestMapping("master/chat")
public class MasterChatController extends BaseController {
	// 在线人列表
	@RequestMapping({ "list" })
	public String mlist(HttpServletRequest request, Model m) {
		User user = getSessionUser();
		if (user == null) {
			return CommonConstant.WEB_LOGIN_INDEX;
		} else {
			m.addAttribute("listHead", "聊天在线");
			return "/master/chat/list";
		}
	}

	// 广播聊天
	@RequestMapping({ "chat" })
	public String mchat(HttpServletRequest request, Model model) {
		User user = getSessionUser();
		if (user == null) {
			return CommonConstant.WEB_LOGIN_INDEX;
		} else {
			request.getSession().setAttribute("uid", user.getId());
			request.getSession().setAttribute("name", user.getNickname());
			request.getSession().setAttribute("toUid", user.getId());// 谁的直播就是谁的ID
		}
		return "/master/chat/chat";
	}

	// 群组聊天
	@RequestMapping({ "chatg" })
	public String gchat(HttpServletRequest request, Model model) {
		String togid = request.getParameter("togid");
		User user = getSessionUser();
		if (user == null) {
			return CommonConstant.WEB_LOGIN_INDEX;
		} else {
			request.getSession().setAttribute("uid", user.getId());
			request.getSession().setAttribute("name", user.getNickname());
			request.getSession().setAttribute("toUid", togid);// 谁的直播就是谁的ID
		}

		return "/master/chat/chatg";
	}

	// 单人聊天
	@RequestMapping({ "chato" })
	public String ochat(HttpServletRequest request, Model model) {
		String touid = request.getParameter("touid");
		User user = getSessionUser();
		if (user == null) {
			return CommonConstant.WEB_LOGIN_INDEX;
		} else {
			request.getSession().setAttribute("uid", user.getId());
			request.getSession().setAttribute("name", user.getNickname());
			request.getSession().setAttribute("toUid", touid);// 谁的直播就是谁的ID
		}

		return "/master/chat/chato";
	}

	//
}
